/* 
 * Copyright (C) 2010---2012 星星(wuweixing)<349446658@qq.com>
 * 
 * This file is part of Wabacus 
 * 
 * Wabacus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.wabacus.system.component.container.page;

import java.util.List;

import com.wabacus.config.Config;
import com.wabacus.config.component.IComponentConfigBean;
import com.wabacus.config.component.application.report.ReportBean;
import com.wabacus.config.component.container.AbsContainerConfigBean;
import com.wabacus.config.component.container.page.PageBean;
import com.wabacus.config.print.AbsPrintProviderConfigBean;
import com.wabacus.config.xml.XmlElementBean;
import com.wabacus.system.ReportRequest;
import com.wabacus.system.assistant.ComponentAssistant;
import com.wabacus.system.buttons.BackButton;
import com.wabacus.system.component.IComponentType;
import com.wabacus.system.component.container.AbsContainerType;
import com.wabacus.system.tags.component.AbsComponentTag;
import com.wabacus.util.Consts;
import com.wabacus.util.Tools;
import com.wabacus.util.UniqueArrayList;

public class DataHtmlType extends AbsContainerType
{
    
    private PageBean pagebean;

    public DataHtmlType(AbsContainerType parentContainerType,IComponentConfigBean comCfgBean,ReportRequest rrequest)
    {
        super(parentContainerType,comCfgBean,rrequest);
        this.pagebean=(PageBean)comCfgBean;
    }

    public void initUrl(IComponentConfigBean applicationConfigBean,ReportRequest rrequest)
    {
        super.initUrl(applicationConfigBean,rrequest);
    }
    
    public List<ReportBean> initDisplayOnPage()
    {
        return super.initDisplayOnPage();
    }

    public void displayOnPage(AbsComponentTag displayTag)
    {
        if(!rrequest.checkPermission(pagebean.getId(),null,null,Consts.PERMISSION_TYPE_DISPLAY))
        {
            wresponse.println("&nbsp;");
            return;
        }
        if(rrequest.checkPermission(pagebean.getId(),Consts.DATA_PART,null,Consts.PERMISSION_TYPE_DISPLAY))
        {
            IComponentType childObjTmp;
            for(String childIdTmp:lstChildrenIds)
            {
                childObjTmp=this.mChildren.get(childIdTmp);
                showHtmlChildObj(childObjTmp);
            }
        }
    }
    public void displayHtmlOnPage(AbsComponentTag displayTag)
    {
        if(!rrequest.checkPermission(pagebean.getId(),null,null,Consts.PERMISSION_TYPE_DISPLAY))
        {
            wresponse.println("&nbsp;");
            return;
        }
        if(rrequest.checkPermission(pagebean.getId(),Consts.DATA_PART,null,Consts.PERMISSION_TYPE_DISPLAY))
        {
            IComponentType childObjTmp;
            for(String childIdTmp:lstChildrenIds)
            {
                childObjTmp=this.mChildren.get(childIdTmp);
                showHtmlChildObj(childObjTmp);
            }
        }
    }
    
    private String showBackButtonInPage()
    {
        StringBuffer resultBuf=new StringBuffer();
        String clickevent=rrequest.getStringAttribute("BACK_ACTION_EVENT","");
        if(rrequest.getLstAncestorUrls()!=null&&rrequest.getLstAncestorUrls().size()>0&&clickevent.equals(""))
        {
            if(this.pagebean.getButtonsBean()!=null&&this.pagebean.getButtonsBean().getcertainTypeButton(BackButton.class)!=null)
            {
                return "";
            }
            BackButton buttonObj=(BackButton)Config.getInstance().getResourceButton(rrequest,rrequest.getPagebean(),Consts.BACK_BUTTON_DEFAULT,
                    BackButton.class);
            resultBuf.append("<table height='3'><tr><td>&nbsp;</td></tr></table>");
            resultBuf.append("<table width='100%' align='center'><tr><td align=\"center\">").append(buttonObj.showButton(rrequest,null)).append(
                    "</td></tr></table>");
        }
        return resultBuf.toString();
    }
    
    private String showStartWebResources()
    {
    	return "";
    }
    
    public String showEndWebResources()
    {
        StringBuffer resultBuf=new StringBuffer();
        return resultBuf.toString();
    }
    
    public String getRealParenttitle()
    {
        return null;//因为<page/>是顶层容器，没有父容器
    }
    
    public void addDynCss(String css)
    {
    }
    
    public void addDynJs(String js)
    {
    }
    
    public AbsContainerConfigBean loadConfig(XmlElementBean eleContainer,AbsContainerConfigBean parent,String tagname)
    {
        return null;
    }
    
    protected String getComponentTypeName()
    {
        return "container.page";
    }
}
